﻿namespace NEvoWeb.Modules.NB_Store
{
    using DotNetNuke.Common.Utilities;
    using DotNetNuke.Entities.Portals;
    using DotNetNuke.Services.FileSystem;
    using DotNetNuke.Services.Localization;
    using Microsoft.VisualBasic;
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.Collections;
    using System.IO;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Web;
    using System.Web.Hosting;

    public class ProductController
    {
        public void AddNewImage(int ProductID, string Lang, string ImagePathFile, string ImageURL, bool Hidden)
        {
            NB_Store_ProductImageInfo objInfo = new NB_Store_ProductImageInfo {
                Hidden = Hidden,
                ImageDesc = "",
                ImageID = -1,
                ImagePath = ImagePathFile,
                Lang = Lang,
                ListOrder = 1,
                ProductID = ProductID,
                ImageURL = ImageURL
            };
            this.UpdateObjProductImage(objInfo);
        }

        public void AddNewModel(NB_Store_ProductsInfo objProductInfo)
        {
            NB_Store_ModelInfo objInfo = new NB_Store_ModelInfo {
                ModelID = -1,
                Barcode = "",
                Lang = objProductInfo.Lang,
                ListOrder = 1,
                ModelName = objProductInfo.ProductName,
                ModelRef = objProductInfo.ProductRef,
                ProductID = objProductInfo.ProductID,
                QtyRemaining = -1,
                QtyTrans = 0,
                QtyTransDate = DateAndTime.Now,
                UnitCost = decimal.Zero
            };
            this.UpdateObjModel(objInfo);
        }

        public void AddNewOption(NB_Store_ProductsInfo objProductInfo)
        {
            NB_Store_OptionInfo objInfo = new NB_Store_OptionInfo {
                OptionID = -1,
                Lang = objProductInfo.Lang,
                ListOrder = 1,
                ProductID = objProductInfo.ProductID,
                OptionDesc = ""
            };
            this.UpdateObjOption(objInfo);
        }

        public void AddNewOptionValue(NB_Store_OptionInfo objOptionInfo)
        {
            NB_Store_OptionValueInfo objInfo = new NB_Store_OptionValueInfo {
                OptionID = objOptionInfo.OptionID,
                Lang = objOptionInfo.Lang,
                ListOrder = 1,
                OptionValueDesc = "",
                AddedCost = decimal.Zero,
                OptionValueID = -1
            };
            this.UpdateObjOptionValue(objInfo);
        }

        public void assignImageByProductRef(int ProductID, string Lang, string ImagesFolder, string HomeDirectory)
        {
            if (this.GetProductImageList(ProductID, Lang).Count == 0)
            {
                NB_Store_ProductsInfo product = this.GetProduct(ProductID, Lang);
                if (product != null)
                {
                    bool hidden = false;
                    FolderInfo folder = FileSystemUtils.GetFolder(product.PortalID, ImagesFolder);
                    if (folder != null)
                    {
                        IEnumerator enumerator=null;
                        ArrayList filesByFolder = FileSystemUtils.GetFilesByFolder(product.PortalID, folder.FolderID);
                        try
                        {
                            enumerator = filesByFolder.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                DotNetNuke.Services.FileSystem.FileInfo current = (DotNetNuke.Services.FileSystem.FileInfo) enumerator.Current;
                                if (current.FileName.ToLower().EndsWith(product.ProductRef.ToLower() + ".jpg"))
                                {
                                    this.AddNewImage(ProductID, Lang, current.FileName, HomeDirectory + "productimages/" + Path.GetFileName(current.FileName), hidden);
                                }
                            }
                        }
                        finally
                        {
                            if (enumerator is IDisposable)
                            {
                                (enumerator as IDisposable).Dispose();
                            }
                        }
                    }
                }
            }
        }

        public string CategoryLangValidation(int PortalID)
        {
            return this.CategoryLangValidation(PortalID, SharedFunctions.GetMerchantCulture(PortalID));
        }

        public string CategoryLangValidation(int PortalID, string Lang)
        {
            IEnumerator enumerator=null;
            CategoryController controller = new CategoryController();
            int num = 0;
            ArrayList categories = controller.GetCategories(PortalID, Lang);
            try
            {
                enumerator = categories.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_CategoriesInfo current = (NB_Store_CategoriesInfo) enumerator.Current;
                    num++;
                    controller.CopyToLanguages(current, false);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return ("Categories Checked based on Merchant Culture of " + Lang + " : " + Conversions.ToString(num));
        }

        private void CopyModels(int ProductID, string Lang, int NewProductID, LocaleCollection supportedLanguages)
        {
            NB_Store_ModelInfo current;
            IEnumerator enumerator=null;
            string lang = "";
            ShipController controller = new ShipController();
            ArrayList list = this.GetModelList(-1, ProductID, Lang, true);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_ModelInfo) enumerator.Current;
                    NB_Store_ShippingRatesInfo objInfo = controller.GetShippingRateByObjID(current.PortalID, current.ModelID, "PRD", -1);
                    current.ModelID = -1;
                    current.ProductID = NewProductID;
                    int num = this.UpdateObjModel(current);
                    if (objInfo != null)
                    {
                        objInfo.ObjectId = num;
                        objInfo.ItemId = -1;
                        controller.UpdateObjShippingRate(objInfo);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            int num4 = supportedLanguages.Count - 1;
            for (int i = 0; i <= num4; i++)
            {
                DictionaryEntry entry = supportedLanguages[i];
                lang = ((Locale) entry.Value).Code;
                ArrayList list2 = this.GetModelList(-1, NewProductID, lang, true);
                list = this.GetModelList(-1, ProductID, lang, true);
                int num5 = list.Count - 1;
                for (int j = 0; j <= num5; j++)
                {
                    current = (NB_Store_ModelInfo) list[j];
                    NB_Store_ModelInfo info2 = (NB_Store_ModelInfo) list2[j];
                    if (current.ModelName != "")
                    {
                        info2.ModelName = current.ModelName;
                        info2.Lang = current.Lang;
                        this.UpdateObjModel(info2);
                    }
                }
            }
        }

        public void CopyModelToLanguages(NB_Store_ModelInfo objInfo, bool ForceOverwrite)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.CopyModelToLanguages(objInfo, lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyModelToLanguages(NB_Store_ModelInfo objInfo, string Lang, bool ForceOverwrite)
        {
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetModel(objInfo.ModelID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjModel(objInfo);
            }
        }

        private void CopyOptions(int ProductID, string Lang, int NewProductID, LocaleCollection supportedLanguages)
        {
            ArrayList list;
            NB_Store_OptionInfo info;
            NB_Store_OptionInfo current;
            IEnumerator enumerator=null;
            string lang = "";
            ArrayList optionList = this.GetOptionList(ProductID, Lang);
            try
            {
                enumerator = optionList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_OptionInfo) enumerator.Current;
                    current.OptionID = -1;
                    current.ProductID = NewProductID;
                    this.UpdateObjOption(current);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            int num4 = supportedLanguages.Count - 1;
            for (int i = 0; i <= num4; i++)
            {
                DictionaryEntry entry = supportedLanguages[i];
                lang = ((Locale) entry.Value).Code;
                list = this.GetOptionList(NewProductID, lang);
                optionList = this.GetOptionList(ProductID, lang);
                int num5 = optionList.Count - 1;
                for (int k = 0; k <= num5; k++)
                {
                    current = (NB_Store_OptionInfo) optionList[k];
                    info = (NB_Store_OptionInfo) list[k];
                    if (current.OptionDesc != "")
                    {
                        info.OptionDesc = current.OptionDesc;
                        info.Lang = current.Lang;
                        this.UpdateObjOption(info);
                    }
                }
            }
            list = this.GetOptionList(NewProductID, Lang);
            optionList = this.GetOptionList(ProductID, Lang);
            int num6 = optionList.Count - 1;
            for (int j = 0; j <= num6; j++)
            {
                current = (NB_Store_OptionInfo) optionList[j];
                info = (NB_Store_OptionInfo) list[j];
                this.CopyOptionValues(current.OptionID, Lang, info.OptionID, supportedLanguages);
            }
        }

        public void CopyOptionToLanguages(NB_Store_OptionInfo objInfo, bool ForceOverwrite)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.CopyOptionToLanguages(objInfo, lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyOptionToLanguages(NB_Store_OptionInfo objInfo, string Lang, bool ForceOverwrite)
        {
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetOption(objInfo.OptionID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjOption(objInfo);
            }
        }

        private void CopyOptionValues(int OptionID, string Lang, int NewOptionID, LocaleCollection supportedLanguages)
        {
            NB_Store_OptionValueInfo current;
            IEnumerator enumerator=null;
            string lang = "";
            ArrayList optionValueList = this.GetOptionValueList(OptionID, Lang);
            try
            {
                enumerator = optionValueList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_OptionValueInfo) enumerator.Current;
                    current.OptionValueID = -1;
                    current.OptionID = NewOptionID;
                    this.UpdateObjOptionValue(current);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            int num3 = supportedLanguages.Count - 1;
            for (int i = 0; i <= num3; i++)
            {
                DictionaryEntry entry = supportedLanguages[i];
                lang = ((Locale) entry.Value).Code;
                ArrayList list = this.GetOptionValueList(NewOptionID, lang);
                optionValueList = this.GetOptionValueList(OptionID, lang);
                if (list.Count != optionValueList.Count)
                {
                    list = (ArrayList) optionValueList.Clone();
                }
                int num4 = optionValueList.Count - 1;
                for (int j = 0; j <= num4; j++)
                {
                    current = (NB_Store_OptionValueInfo) optionValueList[j];
                    NB_Store_OptionValueInfo objInfo = (NB_Store_OptionValueInfo) list[j];
                    if (current.OptionValueDesc != "")
                    {
                        objInfo.OptionValueDesc = current.OptionValueDesc;
                        objInfo.Lang = current.Lang;
                        this.UpdateObjOptionValue(objInfo);
                    }
                }
            }
        }

        public void CopyOptionValueToLanguages(NB_Store_OptionValueInfo objInfo, bool ForceOverwrite)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.CopyOptionValueToLanguages(objInfo, lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyOptionValueToLanguages(NB_Store_OptionValueInfo objInfo, string Lang, bool ForceOverwrite)
        {
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetOptionValue(objInfo.OptionValueID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjOptionValue(objInfo);
            }
        }

        public int CopyProduct(int ProductID)
        {
            NB_Store_ProductsInfo objInfo = null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            string lang = "";
            string code = "";
            int newProductID = -1;
            if (validLocales.Count > 0)
            {
                int num2=0;
                DictionaryEntry entry;
                int num4 = validLocales.Count - 1;
                for (num2 = 0; num2 <= num4; num2++)
                {
                    entry = validLocales[num2];
                    lang = ((Locale) entry.Value).Code;
                    objInfo = this.GetProduct(ProductID, lang);
                    if (objInfo != null)
                    {
                        break;
                    }
                }
                if (objInfo != null)
                {
                    objInfo.ProductID = -1;
                    objInfo.ProductName = objInfo.ProductName + " [Copy]";
                    NB_Store_ProductsInfo info2 = this.UpdateObjProduct(objInfo);
                    if (info2 == null)
                    {
                        return newProductID;
                    }
                    newProductID = info2.ProductID;
                    int num5 = validLocales.Count - 1;
                    for (num2 = 0; num2 <= num5; num2++)
                    {
                        entry = validLocales[num2];
                        code = ((Locale) entry.Value).Code;
                        if (code != lang)
                        {
                            objInfo = this.GetProduct(ProductID, code);
                            if (objInfo != null)
                            {
                                objInfo.ProductID = newProductID;
                                objInfo.ProductName = objInfo.ProductName + " [Copy]";
                                this.UpdateObjProduct(objInfo);
                            }
                        }
                    }
                    this.CopyModels(ProductID, lang, newProductID, validLocales);
                    this.CopyOptions(ProductID, lang, newProductID, validLocales);
                    this.CopyProductImages(ProductID, lang, newProductID, validLocales);
                    this.CopyProductDocs(ProductID, lang, newProductID, validLocales);
                    this.CopyProductCategories(ProductID, newProductID);
                }
            }
            return newProductID;
        }

        private void CopyProductCategories(int ProductID, int NewProductID)
        {
            IEnumerator enumerator=null;
            ArrayList categoriesAssigned = this.GetCategoriesAssigned(ProductID);
            try
            {
                enumerator = categoriesAssigned.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductCategoryInfo current = (NB_Store_ProductCategoryInfo) enumerator.Current;
                    this.UpdateProductCategory(NewProductID, current.CategoryID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        private void CopyProductDocs(int ProductID, string Lang, int NewProductID, LocaleCollection supportedLanguages)
        {
            NB_Store_ProductDocInfo current;
            IEnumerator enumerator=null;
            string lang = "";
            ArrayList productDocList = this.GetProductDocList(ProductID, Lang);
            try
            {
                enumerator = productDocList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_ProductDocInfo) enumerator.Current;
                    current.DocID = -1;
                    current.ProductID = NewProductID;
                    this.UpdateObjProductDoc(current);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            int num3 = supportedLanguages.Count - 1;
            for (int i = 0; i <= num3; i++)
            {
                DictionaryEntry entry = supportedLanguages[i];
                lang = ((Locale) entry.Value).Code;
                ArrayList list = this.GetProductDocList(NewProductID, lang);
                productDocList = this.GetProductDocList(ProductID, lang);
                int num4 = productDocList.Count - 1;
                for (int j = 0; j <= num4; j++)
                {
                    current = (NB_Store_ProductDocInfo) productDocList[j];
                    NB_Store_ProductDocInfo objInfo = (NB_Store_ProductDocInfo) list[j];
                    if (current.DocDesc != "")
                    {
                        objInfo.DocDesc = current.DocDesc;
                        objInfo.Lang = current.Lang;
                        this.UpdateObjProductDoc(objInfo);
                    }
                }
            }
        }

        public void CopyProductDocToLanguages(NB_Store_ProductDocInfo objInfo, bool ForceOverwrite)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.CopyProductDocToLanguages(objInfo, lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyProductDocToLanguages(NB_Store_ProductDocInfo objInfo, string Lang, bool ForceOverwrite)
        {
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetProductDoc(objInfo.DocID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjProductDoc(objInfo);
            }
        }

        private void CopyProductImages(int ProductID, string Lang, int NewProductID, LocaleCollection supportedLanguages)
        {
            NB_Store_ProductImageInfo current;
            IEnumerator enumerator=null;
            string lang = "";
            ArrayList productImageList = this.GetProductImageList(ProductID, Lang);
            try
            {
                enumerator = productImageList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    current = (NB_Store_ProductImageInfo) enumerator.Current;
                    current.ImageID = -1;
                    current.ProductID = NewProductID;
                    this.UpdateObjProductImage(current);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            int num3 = supportedLanguages.Count - 1;
            for (int i = 0; i <= num3; i++)
            {
                DictionaryEntry entry = supportedLanguages[i];
                lang = ((Locale) entry.Value).Code;
                ArrayList list = this.GetProductImageList(NewProductID, lang);
                productImageList = this.GetProductImageList(ProductID, lang);
                int num4 = productImageList.Count - 1;
                for (int j = 0; j <= num4; j++)
                {
                    current = (NB_Store_ProductImageInfo) productImageList[j];
                    NB_Store_ProductImageInfo objInfo = (NB_Store_ProductImageInfo) list[j];
                    if (current.ImageDesc != "")
                    {
                        objInfo.ImageDesc = current.ImageDesc;
                        objInfo.Lang = current.Lang;
                        this.UpdateObjProductImage(objInfo);
                    }
                }
            }
        }

        public void CopyProductImageToLanguages(NB_Store_ProductImageInfo objInfo, bool ForceOverwrite)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.CopyProductImageToLanguages(objInfo, lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyProductImageToLanguages(NB_Store_ProductImageInfo objInfo, string Lang, bool ForceOverwrite)
        {
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetProductImage(objInfo.ImageID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjProductImage(objInfo);
            }
        }

        public void CopyProductToLanguages(NB_Store_ProductsInfo objInfo, bool ForceOverwrite = true)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            string lang = objInfo.Lang;
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string str2 = Conversions.ToString(enumerator.Current);
                    if (lang != str2)
                    {
                        this.CopyProductToLanguages(objInfo, str2, lang, ForceOverwrite);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void CopyProductToLanguages(NB_Store_ProductsInfo objInfo, string Lang, string originalLang, bool ForceOverwrite = true)
        {
            IEnumerator enumerator=null;
            IEnumerator enumerator2=null;
            IEnumerator enumerator4=null;
            IEnumerator enumerator5=null;
            bool flag = true;
            if (!ForceOverwrite)
            {
                if (this.GetProduct(objInfo.ProductID, Lang) == null)
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
            }
            if (flag)
            {
                objInfo.Lang = Lang;
                this.UpdateObjProduct(objInfo);
            }
            ArrayList optionList = this.GetModelList(objInfo.PortalID, objInfo.ProductID, originalLang, true);
            try
            {
                enumerator = optionList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                    this.CopyModelToLanguages(current, Lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            optionList = this.GetOptionList(objInfo.ProductID, originalLang);
            try
            {
                enumerator2 = optionList.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    IEnumerator enumerator3=null;
                    NB_Store_OptionInfo info4 = (NB_Store_OptionInfo) enumerator2.Current;
                    this.CopyOptionToLanguages(info4, Lang, ForceOverwrite);
                    ArrayList optionValueList = this.GetOptionValueList(info4.OptionID, originalLang);
                    try
                    {
                        enumerator3 = optionValueList.GetEnumerator();
                        while (enumerator3.MoveNext())
                        {
                            NB_Store_OptionValueInfo info5 = (NB_Store_OptionValueInfo) enumerator3.Current;
                            this.CopyOptionValueToLanguages(info5, Lang, ForceOverwrite);
                        }
                        continue;
                    }
                    finally
                    {
                        if (enumerator3 is IDisposable)
                        {
                            (enumerator3 as IDisposable).Dispose();
                        }
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            optionList = this.GetProductImageList(objInfo.ProductID, originalLang);
            try
            {
                enumerator4 = optionList.GetEnumerator();
                while (enumerator4.MoveNext())
                {
                    NB_Store_ProductImageInfo info6 = (NB_Store_ProductImageInfo) enumerator4.Current;
                    this.CopyProductImageToLanguages(info6, Lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator4 is IDisposable)
                {
                    (enumerator4 as IDisposable).Dispose();
                }
            }
            optionList = this.GetProductDocList(objInfo.ProductID, originalLang);
            try
            {
                enumerator5 = optionList.GetEnumerator();
                while (enumerator5.MoveNext())
                {
                    NB_Store_ProductDocInfo info = (NB_Store_ProductDocInfo) enumerator5.Current;
                    this.CopyProductDocToLanguages(info, Lang, ForceOverwrite);
                }
            }
            finally
            {
                if (enumerator5 is IDisposable)
                {
                    (enumerator5 as IDisposable).Dispose();
                }
            }
        }

        public void CreateProductOptionValues(NB_Store_OptionInfo objOptionInfo, int CategoryOptionID)
        {
            ArrayList optionValueList = this.GetOptionValueList(CategoryOptionID, objOptionInfo.Lang);
            if ((optionValueList != null) && (optionValueList.Count > 0))
            {
                IEnumerator enumerator=null;
                try
                {
                    enumerator = optionValueList.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_OptionValueInfo current = (NB_Store_OptionValueInfo) enumerator.Current;
                        current.OptionValueID = -1;
                        current.OptionID = objOptionInfo.OptionID;
                        this.UpdateObjOptionValue(current);
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
            }
        }

        public int CheckIfProductPurchased(int ProductID, int UserID)
        {
            return DataProvider.Instance().CheckIfProductPurchased(ProductID, UserID);
        }

        public void DeleteModel(int PortalID, int ModelID)
        {
            IEnumerator enumerator=null;
            DataProvider.Instance().DeleteNB_Store_Model(ModelID);
            ShipController controller = new ShipController();
            ArrayList shippingMethodList = controller.GetShippingMethodList(PortalID);
            try
            {
                enumerator = shippingMethodList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ShippingMethodInfo current = (NB_Store_ShippingMethodInfo) enumerator.Current;
                    NB_Store_ShippingRatesInfo info = controller.GetShippingRateByObjID(PortalID, ModelID, "PRD", current.ShipMethodID);
                    if (info != null)
                    {
                        DataProvider.Instance().DeleteNB_Store_ShippingRates(info.ItemId);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void DeleteOption(int OptionID)
        {
            DataProvider.Instance().DeleteNB_Store_Option(OptionID);
        }

        public void DeleteOptionValue(int OptionValueID)
        {
            DataProvider.Instance().DeleteNB_Store_OptionValue(OptionValueID);
        }

        public void DeleteProduct(int ProductID)
        {
            IEnumerator enumerator=null;
            IEnumerator enumerator2=null;
            ArrayList productImageList = this.GetProductImageList(ProductID, SharedFunctions.GetCurrentCulture());
            try
            {
                enumerator = productImageList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductImageInfo current = (NB_Store_ProductImageInfo) enumerator.Current;
                    this.DeleteProductImage(current.ImageID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            productImageList = this.GetProductDocList(ProductID, SharedFunctions.GetCurrentCulture());
            try
            {
                enumerator2 = productImageList.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    NB_Store_ProductDocInfo info2 = (NB_Store_ProductDocInfo) enumerator2.Current;
                    this.DeleteProductDoc(info2.DocID);
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            this.DeleteProductRelatedByProduct(ProductID);
            DataProvider.Instance().DeleteNB_Store_Products(ProductID);
        }

        public void DeleteProductCategory(int ProductID)
        {
            this.DeleteProductCategory(ProductID, -1);
        }

        public void DeleteProductCategory(int ProductID, int CategoryID)
        {
            DataProvider.Instance().DeleteProductCategory(ProductID, CategoryID);
        }

        public void DeleteProductDoc(int DocID)
        {
            DataProvider.Instance().DeleteNB_Store_ProductDoc(DocID);
        }

        public void DeleteProductImage(int ImageID)
        {
            DataProvider.Instance().DeleteNB_Store_ProductImage(ImageID);
        }

        public void DeleteProductModels(NB_Store_ProductsInfo objProductInfo)
        {
            IEnumerator enumerator=null;
            ArrayList list = this.GetModelList(objProductInfo.PortalID, objProductInfo.ProductID, objProductInfo.Lang, true);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                    this.DeleteModel(objProductInfo.PortalID, current.ModelID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void DeleteProductOptions(NB_Store_ProductsInfo objProductInfo)
        {
            IEnumerator enumerator=null;
            ArrayList optionList = this.GetOptionList(objProductInfo.ProductID, objProductInfo.Lang);
            try
            {
                enumerator = optionList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OptionInfo current = (NB_Store_OptionInfo) enumerator.Current;
                    this.DeleteOption(current.OptionID);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void DeleteProductRelated(int RelatedID)
        {
            DataProvider.Instance().DeleteNB_Store_ProductRelated(RelatedID);
        }

        public void DeleteProductRelatedByProduct(int ProductID)
        {
            DataProvider.Instance().DeleteNB_Store_ProductRelatedByProduct(ProductID);
        }

        public string DocValidation(int PortalID, string DocMapPath, bool DoFix)
        {
            IEnumerator enumerator=null;
            ProductController controller = new ProductController();
            int num = 0;
            int num2 = 0;
            ArrayList productDocExportList = this.GetProductDocExportList(PortalID);
            try
            {
                enumerator = productDocExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductDocInfo current = (NB_Store_ProductDocInfo) enumerator.Current;
                    if (!current.DocPath.ToLower().StartsWith(DocMapPath.ToLower()))
                    {
                        num++;
                        if (DoFix)
                        {
                            current.DocPath = DocMapPath + @"\" + Path.GetFileName(current.DocPath);
                            if (File.Exists(current.DocPath))
                            {
                                current.Lang = "";
                                controller.UpdateObjProductDoc(current);
                                if (current != null)
                                {
                                    SharedFunctions.UpdateLog("Update Doc - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                                }
                            }
                            else if (current != null)
                            {
                                SharedFunctions.UpdateLog("Delete Doc - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                                controller.DeleteProductDoc(current.DocID);
                            }
                            num2++;
                        }
                    }
                    else if (!File.Exists(current.DocPath))
                    {
                        num++;
                        if (DoFix)
                        {
                            SharedFunctions.UpdateLog("Delete Doc - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                            controller.DeleteProductDoc(current.DocID);
                            num2++;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return ("ERRORS: " + Conversions.ToString(num) + "  FIX: " + Conversions.ToString(num2));
        }

        public ArrayList GetCategoriesAssigned(int ProductID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductCategoriesAssigned(ProductID), typeof(NB_Store_ProductCategoryInfo));
        }

        public decimal GetFromPrice(int PortalID, int ProductID)
        {
            IEnumerator enumerator=null;
            decimal minusOne = decimal.MinusOne;
            ArrayList list = this.GetModelList(PortalID, ProductID, SharedFunctions.GetCurrentCulture(), true);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                    if (decimal.Compare(minusOne, decimal.Zero) < 0)
                    {
                        minusOne = current.UnitCost;
                    }
                    else if (decimal.Compare(minusOne, current.UnitCost) > 0)
                    {
                        minusOne = current.UnitCost;
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return minusOne;
        }

        public string GetFromPriceCurrency(int PortalID, int ProductID)
        {
            return SharedFunctions.FormatToStoreCurrency(Convert.ToDouble(this.GetFromPrice(PortalID, ProductID)));
        }

        public NB_Store_ModelInfo GetModel(int ModelID, string Lang)
        {
            return (NB_Store_ModelInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_Model(ModelID, Lang), typeof(NB_Store_ModelInfo));
        }

        public NB_Store_ModelInfo GetModelByProductID(int ProductID, string Lang)
        {
            return (NB_Store_ModelInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_ModelByProductID(ProductID, Lang), typeof(NB_Store_ModelInfo));
        }

        public NB_Store_ModelInfo GetModelByRef(string ModelRef, string Lang)
        {
            return (NB_Store_ModelInfo) CBO.FillObject(DataProvider.Instance().GetModelByRef(-1, ModelRef, Lang), typeof(NB_Store_ModelInfo));
        }

        public NB_Store_ModelInfo GetModelByRef(int ProductID, string ModelRef, string Lang)
        {
            return (NB_Store_ModelInfo) CBO.FillObject(DataProvider.Instance().GetModelByRef(ProductID, ModelRef, Lang), typeof(NB_Store_ModelInfo));
        }

        public ArrayList GetModelDeletedList(int PortalID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_DeletedModels(PortalID), typeof(NB_Store_ModelInfo));
        }

        public int GetModelInOrders(int ModelID)
        {
            return DataProvider.Instance().GetModelInOrders(ModelID);
        }

        public ArrayList GetModelInStockList(int ProductID, string Lang, bool IsDealer)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ModelsInStock(ProductID, Lang, IsDealer), typeof(NB_Store_ModelInfo));
        }

        public ArrayList GetModelList(int PortalID, string Lang, bool IsDealer)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_Models(PortalID, -1, Lang, IsDealer), typeof(NB_Store_ModelInfo));
        }

        public ArrayList GetModelList(int PortalID, int ProductID, string Lang, bool IsDealer)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_Models(PortalID, ProductID, Lang, IsDealer), typeof(NB_Store_ModelInfo));
        }

        public ArrayList GetModelStockList(int PortalID, string Filter, string Lang, int CategoryID, bool IsDealer)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ModelStockList(PortalID, Filter, Lang, CategoryID, 1, 0, IsDealer), typeof(NB_Store_ModelInfo));
        }

        public ArrayList GetModelStockList(int PortalID, string Filter, string Lang, int CategoryID, int PageIndex, int PageSize, bool IsDealer)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ModelStockList(PortalID, Filter, Lang, CategoryID, PageIndex, PageSize, IsDealer), typeof(NB_Store_ModelInfo));
        }

        public int GetModelStockListSize(int PortalID, string Filter, string Lang, int CategoryID, bool IsDealer)
        {
            return DataProvider.Instance().GetNB_Store_ModelStockListSize(PortalID, Filter, Lang, CategoryID, IsDealer);
        }

        public NB_Store_OptionInfo GetOption(int OptionID, string Lang)
        {
            return (NB_Store_OptionInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_Option(OptionID, Lang), typeof(NB_Store_OptionInfo));
        }

        public ArrayList GetOptionList(int ProductID, string Lang)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_Options(ProductID, Lang), typeof(NB_Store_OptionInfo));
        }

        public NB_Store_OptionValueInfo GetOptionValue(int OptionValueID, string Lang)
        {
            return (NB_Store_OptionValueInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_OptionValue(OptionValueID, Lang), typeof(NB_Store_OptionValueInfo));
        }

        public ArrayList GetOptionValueList(int OptionID, string Lang)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_OptionValues(OptionID, Lang), typeof(NB_Store_OptionValueInfo));
        }

        public ArrayList GetOptionValueListWithInterface(int OptionID, string Lang)
        {
            ArrayList optionValueList = this.GetOptionValueList(OptionID, Lang);
            if (OptionInterface.Instance() != null)
            {
                PortalSettings currentPortalSettings = PortalController.GetCurrentPortalSettings();
                optionValueList = OptionInterface.Instance().GetOptionValueList(currentPortalSettings.PortalId, OptionID, Lang, optionValueList);
            }
            return optionValueList;
        }

        public NB_Store_ProductsInfo GetProduct(int ProductID, string Lang)
        {
            return (NB_Store_ProductsInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_Products(ProductID, Lang), typeof(NB_Store_ProductsInfo));
        }

        public NB_Store_ProductsInfo GetProductByRef(int PortalID, string ProductRef, string Lang)
        {
            return (NB_Store_ProductsInfo) CBO.FillObject(DataProvider.Instance().GetProductByRef(PortalID, ProductRef, Lang), typeof(NB_Store_ProductsInfo));
        }

        public int GetProductCount(int PortalID)
        {
            return DataProvider.Instance().GetProductCount(PortalID);
        }

        public NB_Store_ProductDocInfo GetProductDoc(int DocID, string Lang)
        {
            return (NB_Store_ProductDocInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_ProductDoc(DocID, Lang), typeof(NB_Store_ProductDocInfo));
        }

        public ArrayList GetProductDocExportList(int PortalID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductDocExportList(PortalID), typeof(NB_Store_ProductDocInfo));
        }

        public ArrayList GetProductDocList(int ProductID, string Lang)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductDocList(ProductID, Lang), typeof(NB_Store_ProductDocInfo));
        }

        public ArrayList GetProductExportList(int PortalID, string Lang, bool DeletedOnly)
        {
            return this.GetProductExportList(PortalID, Lang, DeletedOnly, "");
        }

        public ArrayList GetProductExportList(int PortalID, string Lang, bool DeletedOnly, string CategoryList)
        {
            return CBO.FillCollection(DataProvider.Instance().GetProductExportList(PortalID, Lang, DeletedOnly, CategoryList), typeof(NB_Store_ProductsInfo));
        }

        public NB_Store_ProductImageInfo GetProductImage(int ImageID, string Lang)
        {
            return (NB_Store_ProductImageInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_ProductImage(ImageID, Lang), typeof(NB_Store_ProductImageInfo));
        }

        public ArrayList GetProductImageExportList(int PortalID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetProductExportImages(PortalID), typeof(NB_Store_ProductImageInfo));
        }

        public ArrayList GetProductImageList(int ProductID, string Lang)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductImages(ProductID, Lang), typeof(NB_Store_ProductImageInfo));
        }

        public ArrayList GetProductInArray(int ProductID, string Lang)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_Products(ProductID, Lang), typeof(ProductListInfo));
        }

        public int GetProductInOrders(int ProductID)
        {
            return DataProvider.Instance().GetProductInOrders(ProductID);
        }

        public string getProductLinkXML(NB_Store_ProductsInfo objPInfo, int ProductTabID, int CatID)
        {
            string str2 = "";
            return ((str2 + "<link>") + SharedFunctions.GetProductUrl(objPInfo.PortalID, ProductTabID, objPInfo, CatID, false) + "</link>");
        }

        public string getProductLinkXML(ProductListInfo objPInfo, int ProductTabID, int CatID)
        {
            string str2 = "";
            return ((str2 + "<link>") + SharedFunctions.GetProductUrl(objPInfo.PortalID, ProductTabID, objPInfo, CatID, false) + "</link>");
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, "", false, false, "", false, 0, 1, 0x1869f, false, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, int PageIndex, int Pagesize, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, "", false, false, "", false, 0, PageIndex, Pagesize, false, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, bool SearchDescription, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, SearchText, false, false, "", false, 0, 1, 0x1869f, SearchDescription, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, bool GetArchived, bool SearchDescription, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, SearchText, GetArchived, false, "", false, 0, 1, 0x1869f, SearchDescription, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, int PageIndex, int Pagesize, bool SearchDescription, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, SearchText, false, false, "", false, 0, PageIndex, Pagesize, SearchDescription, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, bool GetArchived, int PageIndex, int Pagesize, bool SearchDescription, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, SearchText, GetArchived, false, "", false, 0, PageIndex, Pagesize, SearchDescription, isDealer);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, bool GetArchived, bool FeaturedOnly, string OrderBY, bool OrderDESC, int ReturnLimit, int PageIndex, int Pagesize, bool SearchDescription, bool isDealer)
        {
            return this.GetProductList(PortalID, CategoryID, Lang, SearchText, GetArchived, FeaturedOnly, OrderBY, OrderDESC, ReturnLimit, PageIndex, Pagesize, SearchDescription, isDealer, "", false);
        }

        public ArrayList GetProductList(int PortalID, int CategoryID, string Lang, string SearchText, bool GetArchived, bool FeaturedOnly, string OrderBY, bool OrderDESC, int ReturnLimit, int PageIndex, int Pagesize, bool SearchDescription, bool isDealer, string CategoryList, bool ExcludeFeatured)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_Productss(PortalID, CategoryID, Lang, SearchText, GetArchived, FeaturedOnly, OrderBY, OrderDESC, ReturnLimit, PageIndex, Pagesize, SearchDescription, isDealer, CategoryList, ExcludeFeatured), typeof(ProductListInfo));
        }

        public ProductListInfo GetProductListInfo(int ProductID, string Lang)
        {
            return (ProductListInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_Products(ProductID, Lang), typeof(ProductListInfo));
        }

        public int GetProductListSize(int PortalID, int CategoryID, string Lang, string SearchText, bool GetArchived, bool FeaturedOnly, bool SearchDescription, bool isDealer, string CategoryList, bool ExcludeFeatured)
        {
            return DataProvider.Instance().GetProductListSize(PortalID, CategoryID, Lang, SearchText, GetArchived, FeaturedOnly, SearchDescription, isDealer, CategoryList, ExcludeFeatured);
        }

        public NB_Store_ProductRelatedInfo GetProductRelated(int RelatedID)
        {
            return (NB_Store_ProductRelatedInfo) CBO.FillObject(DataProvider.Instance().GetNB_Store_ProductRelated(RelatedID), typeof(NB_Store_ProductRelatedInfo));
        }

        public ArrayList GetProductRelatedArray(int PortalID, int ProductID, string Lang, int RelatedType, bool GetAll)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductRelatedList(PortalID, ProductID, Lang, RelatedType, GetAll), typeof(NB_Store_ProductRelatedInfo));
        }

        public ArrayList GetProductRelatedList(int PortalID, int ProductID, string Lang, int RelatedType, bool GetAll)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductRelatedList(PortalID, ProductID, Lang, RelatedType, GetAll), typeof(NB_Store_ProductRelatedListInfo));
        }

        public ArrayList GetProductSelectDocList(string Lang, string FilterText, int PortalID)
        {
            return CBO.FillCollection(DataProvider.Instance().GetNB_Store_ProductSelectDocList(Lang, FilterText, PortalID), typeof(NB_Store_ProductSelectDocInfo));
        }

        private Hashtable getSubCategoryHashTable(int PortalID, string ParentCategoryID)
        {
            string cacheKey = "SubCategoryHashTable_" + PortalID.ToString() + "_" + ParentCategoryID.ToString();
            if ((DataCache.GetCache(cacheKey) == null) | SharedFunctions.GetStoreSettingBoolean(PortalID, "debug.mode"))
            {
                CategoryController controller = new CategoryController();
                Hashtable objObject = new Hashtable();
                ArrayList categories = controller.GetCategories(PortalID, SharedFunctions.GetCurrentCulture());
                string[] strArray = (controller.GetSubCategoryList(categories, Conversions.ToInteger(ParentCategoryID)) + ParentCategoryID.ToString()).Split(new char[] { ',' });
                int upperBound = strArray.GetUpperBound(0);
                for (int i = 0; i <= upperBound; i++)
                {
                    objObject.Add(strArray[i], strArray[i]);
                }
                DataCache.SetCache(cacheKey, objObject, DateAndTime.DateAdd(DateInterval.Day, 1.0, DateAndTime.Now));
                return objObject;
            }
            return (Hashtable) DataCache.GetCache(cacheKey);
        }

        public string ImageValidation(int PortalID, string WebMapPath, bool DoFix)
        {
            IEnumerator enumerator=null;
            ProductController controller = new ProductController();
            int num = 0;
            int num2 = 0;
            ArrayList productImageExportList = this.GetProductImageExportList(PortalID);
            try
            {
                enumerator = productImageExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductImageInfo current = (NB_Store_ProductImageInfo) enumerator.Current;
                    if ((WebMapPath.TrimEnd(new char[] { '\\' }) + Strings.Replace(current.ImageURL, "/", @"\", 1, -1, CompareMethod.Binary)) != current.ImagePath)
                    {
                        num++;
                        if (DoFix)
                        {
                            current.ImagePath = WebMapPath.TrimEnd(new char[] { '\\' }) + Strings.Replace(current.ImageURL, "/", @"\", 1, -1, CompareMethod.Binary);
                            if (File.Exists(current.ImagePath))
                            {
                                controller.UpdateObjProductImageOnly(current);
                                if (current != null)
                                {
                                    SharedFunctions.UpdateLog("Update Image - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                                }
                            }
                            else
                            {
                                if (current != null)
                                {
                                    SharedFunctions.UpdateLog("Delete Image - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                                }
                                controller.DeleteProductImage(current.ImageID);
                            }
                            num2++;
                        }
                    }
                    else if (!File.Exists(current.ImagePath))
                    {
                        num++;
                        if (DoFix)
                        {
                            SharedFunctions.UpdateLog("Delete Image - " + MethodBase.GetCurrentMethod().Name + " - " + XmlUtils.Serialize(current));
                            controller.DeleteProductImage(current.ImageID);
                            num2++;
                        }
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return ("ERRORS: " + Conversions.ToString(num) + "  FIX: " + Conversions.ToString(num2));
        }

        public bool IsInCategory(int PortalID, int ProductID, string CategoryID)
        {
            bool flag2 = false;
            string cacheKey = "";
            cacheKey = SharedFunctions.GetCacheKey("IsInCategory" + CategoryID, PortalID, ProductID);
            if (((DataCache.GetCache(cacheKey) == null) & (cacheKey != "")) | SharedFunctions.GetStoreSettingBoolean(PortalID, "debug.mode", "None"))
            {
                IEnumerator enumerator=null;
                ArrayList categoriesAssigned = this.GetCategoriesAssigned(ProductID);
                try
                {
                    enumerator = categoriesAssigned.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_ProductCategoryInfo current = (NB_Store_ProductCategoryInfo) enumerator.Current;
                        if (Conversions.ToDouble(CategoryID) == current.CategoryID)
                        {
                            return true;
                        }
                    }
                    return flag2;
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                return flag2;
            }
            return Conversions.ToBoolean(DataCache.GetCache(cacheKey));
        }

        public bool IsInCategoryOrSubCategory(int PortalID, int ProductID, string CategoryID)
        {
            bool flag2 = false;
            string cacheKey = "";
            cacheKey = SharedFunctions.GetCacheKey("IsInCategoryOrSubCategory" + CategoryID, PortalID, ProductID);
            if (((DataCache.GetCache(cacheKey) == null) & (cacheKey != "")) | SharedFunctions.GetStoreSettingBoolean(PortalID, "debug.mode", "None"))
            {
                IEnumerator enumerator=null;
                Hashtable hashtable = this.getSubCategoryHashTable(PortalID, CategoryID);
                ArrayList categoriesAssigned = this.GetCategoriesAssigned(ProductID);
                try
                {
                    enumerator = categoriesAssigned.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        NB_Store_ProductCategoryInfo current = (NB_Store_ProductCategoryInfo) enumerator.Current;
                        if (hashtable.ContainsKey(current.CategoryID.ToString()))
                        {
                            flag2 = true;
                            DataCache.SetCache(cacheKey, flag2.ToString(), DateAndTime.DateAdd(DateInterval.Day, 1.0, DateAndTime.Now));
                            return flag2;
                        }
                    }
                    return flag2;
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                return flag2;
            }
            return Conversions.ToBoolean(DataCache.GetCache(cacheKey));
        }

        public void NotAvailableProductRelated(int ProductID, bool Flag)
        {
            DataProvider.Instance().NotAvailableProductRelated(ProductID, Flag);
        }

        public string ProductLangValidation(int PortalID)
        {
            return this.ProductLangValidation(PortalID, SharedFunctions.GetMerchantCulture(PortalID));
        }

        public string ProductLangValidation(int PortalID, string Lang)
        {
            IEnumerator enumerator=null;
            int num = 0;
            ArrayList list = this.GetProductExportList(PortalID, Lang, false);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductsInfo current = (NB_Store_ProductsInfo) enumerator.Current;
                    num++;
                    this.CopyProductToLanguages(current, false);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return ("Products Checked based on Merchant Culture of " + Lang + " : " + Conversions.ToString(num));
        }

        public void PurgeDocs(PortalSettings PortalSettings, string DocDirectory)
        {
            IEnumerator enumerator=null;
            Hashtable hashtable = new Hashtable();
            ArrayList productDocExportList = this.GetProductDocExportList(PortalSettings.PortalId);
            try
            {
                enumerator = productDocExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductDocInfo current = (NB_Store_ProductDocInfo) enumerator.Current;
                    if (!hashtable.ContainsValue(current.DocPath.ToLower()))
                    {
                        hashtable.Add(current.DocID, current.DocPath.ToLower());
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, DocDirectory);
            if (folder != null)
            {
                IEnumerator enumerator2=null;
                productDocExportList = FileSystemUtils.GetFilesByFolder(PortalSettings.PortalId, folder.FolderID);
                try
                {
                    enumerator2 = productDocExportList.GetEnumerator();
                    while (enumerator2.MoveNext())
                    {
                        DotNetNuke.Services.FileSystem.FileInfo info = (DotNetNuke.Services.FileSystem.FileInfo) enumerator2.Current;
                        if (!hashtable.ContainsValue((PortalSettings.HomeDirectoryMapPath + DocDirectory + @"\" + info.FileName).ToLower()))
                        {
                            FileSystemUtils.DeleteFile(PortalSettings.HomeDirectoryMapPath + DocDirectory + @"\" + info.FileName, PortalSettings, true);
                        }
                    }
                }
                finally
                {
                    if (enumerator2 is IDisposable)
                    {
                        (enumerator2 as IDisposable).Dispose();
                    }
                }
            }
        }

        public void PurgeImages(PortalSettings PortalSettings, string ImageDirectory)
        {
            IEnumerator enumerator=null;
            IEnumerator enumerator2=null;
            Hashtable hashtable = new Hashtable();
            CategoryController controller = new CategoryController();
            ArrayList productImageExportList = this.GetProductImageExportList(PortalSettings.PortalId);
            try
            {
                enumerator = productImageExportList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductImageInfo current = (NB_Store_ProductImageInfo) enumerator.Current;
                    if (!hashtable.ContainsValue(current.ImagePath.ToLower()))
                    {
                        hashtable.Add(current.ImageID, current.ImagePath.ToLower());
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            productImageExportList = controller.GetCategories(PortalSettings.PortalId, SharedFunctions.GetCurrentCulture(), -1, true, true);
            try
            {
                enumerator2 = productImageExportList.GetEnumerator();
                while (enumerator2.MoveNext())
                {
                    NB_Store_CategoriesInfo info3 = (NB_Store_CategoriesInfo) enumerator2.Current;
                    if (((info3.ImageURL != "") && !hashtable.ContainsValue(HostingEnvironment.MapPath(info3.ImageURL).ToLower())) && (info3.ImageURL != ""))
                    {
                        hashtable.Add("CAT" + info3.CategoryID.ToString(), HostingEnvironment.MapPath(info3.ImageURL).ToLower());
                    }
                }
            }
            finally
            {
                if (enumerator2 is IDisposable)
                {
                    (enumerator2 as IDisposable).Dispose();
                }
            }
            FolderInfo folder = FileSystemUtils.GetFolder(PortalSettings.PortalId, ImageDirectory);
            if (folder != null)
            {
                IEnumerator enumerator3=null;
                productImageExportList = FileSystemUtils.GetFilesByFolder(PortalSettings.PortalId, folder.FolderID);
                try
                {
                    enumerator3 = productImageExportList.GetEnumerator();
                    while (enumerator3.MoveNext())
                    {
                        DotNetNuke.Services.FileSystem.FileInfo info = (DotNetNuke.Services.FileSystem.FileInfo) enumerator3.Current;
                        if (!hashtable.ContainsValue((PortalSettings.HomeDirectoryMapPath + ImageDirectory + @"\" + info.FileName).ToLower()))
                        {
                            FileSystemUtils.DeleteFile(PortalSettings.HomeDirectoryMapPath + ImageDirectory + @"\" + info.FileName, PortalSettings, true);
                        }
                    }
                }
                finally
                {
                    if (enumerator3 is IDisposable)
                    {
                        (enumerator3 as IDisposable).Dispose();
                    }
                }
            }
        }

        public void PurgeModels(int PortalID)
        {
            IEnumerator enumerator=null;
            ArrayList modelDeletedList = this.GetModelDeletedList(PortalID);
            try
            {
                enumerator = modelDeletedList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ModelInfo current = (NB_Store_ModelInfo) enumerator.Current;
                    if (this.GetModelInOrders(current.ModelID) == 0)
                    {
                        this.DeleteModel(PortalID, current.ModelID);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void PurgeProducts(int PortalID)
        {
            IEnumerator enumerator=null;
            LocaleCollection validLocales = SharedFunctions.GetValidLocales();
            try
            {
                enumerator = validLocales.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    string lang = Conversions.ToString(enumerator.Current);
                    this.PurgeProducts(PortalID, lang);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void PurgeProducts(int PortalID, string Lang)
        {
            IEnumerator enumerator=null;
            ArrayList list = this.GetProductExportList(PortalID, Lang, true);
            try
            {
                enumerator = list.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_ProductsInfo current = (NB_Store_ProductsInfo) enumerator.Current;
                    if (this.GetProductInOrders(current.ProductID) == 0)
                    {
                        this.DeleteProduct(current.ProductID);
                    }
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void RemoveModelQtyTrans(int OrderID)
        {
            IEnumerator enumerator=null;
            ArrayList orderDetailList = new OrderController().GetOrderDetailList(OrderID);
            try
            {
                enumerator = orderDetailList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                    this.UpdateModelQtyTrans(current.ModelID, current.Quantity * -1);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void UpdateModelQtyTrans(int OrderID)
        {
            IEnumerator enumerator=null;
            ArrayList orderDetailList = new OrderController().GetOrderDetailList(OrderID);
            try
            {
                enumerator = orderDetailList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                    this.UpdateModelQtyTrans(current.ModelID, current.Quantity);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void UpdateModelQtyTrans(int ModelID, int QtyTrans)
        {
            NB_Store_ModelInfo model = this.GetModel(ModelID, SharedFunctions.GetCurrentCulture());
            if (model != null)
            {
                if (DateTime.Compare(DateAndTime.Now, DateAndTime.DateAdd(DateInterval.Minute, 10.0, model.QtyTransDate)) < 0)
                {
                    model.QtyTrans = QtyTrans + model.QtyTrans;
                }
                else
                {
                    model.QtyTrans = QtyTrans;
                }
                model.QtyTransDate = DateAndTime.Now;
                if (model.QtyTrans < 0)
                {
                    model.QtyTrans = 0;
                }
                this.UpdateObjModel(model);
            }
        }

        public int UpdateObjModel(NB_Store_ModelInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_Model(objInfo.ModelID, objInfo.ProductID, objInfo.ListOrder, objInfo.UnitCost, objInfo.Barcode, objInfo.ModelRef, objInfo.Lang, objInfo.ModelName, objInfo.QtyRemaining, objInfo.QtyTrans, objInfo.QtyTransDate, objInfo.Deleted, objInfo.QtyStockSet, objInfo.DealerCost, objInfo.PurchaseCost, objInfo.XMLData, objInfo.Extra, objInfo.DealerOnly, objInfo.Allow);
        }

        public NB_Store_OptionInfo UpdateObjOption(NB_Store_OptionInfo objInfo)
        {
            return (NB_Store_OptionInfo) CBO.FillObject(DataProvider.Instance().UpdateNB_Store_Option(objInfo.OptionID, objInfo.ProductID, objInfo.ListOrder, objInfo.Lang, objInfo.OptionDesc, objInfo.Attributes), typeof(NB_Store_OptionInfo));
        }

        public int UpdateObjOptionValue(NB_Store_OptionValueInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_OptionValue(objInfo.OptionValueID, objInfo.OptionID, objInfo.AddedCost, objInfo.ListOrder, objInfo.Lang, objInfo.OptionValueDesc);
        }

        public NB_Store_ProductsInfo UpdateObjProduct(NB_Store_ProductsInfo objInfo)
        {
            return (NB_Store_ProductsInfo) CBO.FillObject(DataProvider.Instance().UpdateNB_Store_Products(objInfo.ProductID, objInfo.PortalID, objInfo.TaxCategoryID, objInfo.Featured, objInfo.Archived, objInfo.CreatedByUser, objInfo.CreatedDate, objInfo.IsDeleted, objInfo.ProductRef, objInfo.Lang, objInfo.Summary, objInfo.Description, objInfo.Manufacturer, objInfo.ProductName, objInfo.XMLData, objInfo.SEOName, objInfo.TagWords, objInfo.IsHidden), typeof(NB_Store_ProductsInfo));
        }

        public void UpdateObjProductCategory(NB_Store_ProductCategoryInfo objInfo)
        {
            DataProvider.Instance().UpdateProductCategory(objInfo.ProductID, objInfo.CategoryID);
        }

        public int UpdateObjProductDoc(NB_Store_ProductDocInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_ProductDoc(objInfo.DocID, objInfo.ProductID, objInfo.DocPath, objInfo.ListOrder, objInfo.Hidden, HttpUtility.UrlPathEncode(objInfo.FileName), objInfo.FileExt, objInfo.Lang, objInfo.DocDesc);
        }

        public int UpdateObjProductImage(NB_Store_ProductImageInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_ProductImage(objInfo.ImageID, objInfo.ProductID, objInfo.ImagePath, objInfo.ListOrder, objInfo.Hidden, objInfo.Lang, objInfo.ImageDesc, objInfo.ImageURL);
        }

        public void UpdateObjProductImageOnly(NB_Store_ProductImageInfo objInfo)
        {
            DataProvider.Instance().UpdateNB_Store_ProductImageOnly(objInfo.ImageID, objInfo.ProductID, objInfo.ImagePath, objInfo.ListOrder, objInfo.Hidden, objInfo.ImageURL);
        }

        public int UpdateObjProductRelated(NB_Store_ProductRelatedInfo objInfo)
        {
            return DataProvider.Instance().UpdateNB_Store_ProductRelated(objInfo.RelatedID, objInfo.PortalID, objInfo.ProductID, objInfo.RelatedProductID, objInfo.DiscountAmt, objInfo.DiscountPercent, objInfo.ProductQty, objInfo.MaxQty, objInfo.RelatedType, objInfo.Disabled, objInfo.NotAvailable, objInfo.BiDirectional);
        }

        public void UpdateProductCategory(int ProductID, int CategoryID)
        {
            DataProvider.Instance().UpdateProductCategory(ProductID, CategoryID);
        }

        public void UpdateStockLevel(int OrderID)
        {
            IEnumerator enumerator=null;
            ArrayList orderDetailList = new OrderController().GetOrderDetailList(OrderID);
            try
            {
                enumerator = orderDetailList.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    NB_Store_OrderDetailsInfo current = (NB_Store_OrderDetailsInfo) enumerator.Current;
                    this.UpdateStockLevel(current.ModelID, current.Quantity);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
        }

        public void UpdateStockLevel(int ModelID, int Qty)
        {
            NB_Store_ModelInfo model = this.GetModel(ModelID, SharedFunctions.GetCurrentCulture());
            if ((model != null) && (model.QtyRemaining > 0))
            {
                if (model.QtyRemaining > 0)
                {
                    model.QtyRemaining -= Qty;
                    model.QtyTrans -= Qty;
                }
                if (model.QtyRemaining < 0)
                {
                    model.QtyRemaining = 0;
                }
                if (model.QtyTrans < 0)
                {
                    model.QtyTrans = 0;
                }
                this.UpdateObjModel(model);
            }
        }

        public string xmlGetProduct(int ProdID, string Lang, int ProductTabID = -1, int CatID = -1)
        {
            IEnumerator enumerator=null;
            Export export = new Export();
            ArrayList productInArray = this.GetProductInArray(ProdID, Lang);
            string str = "";
            str = str + "<root>";
            try
            {
                enumerator = productInArray.GetEnumerator();
                while (enumerator.MoveNext())
                {
                    ProductListInfo current = (ProductListInfo) enumerator.Current;
                    if (ProductTabID >= 0)
                    {
                        str = str + this.getProductLinkXML(current, ProductTabID, CatID);
                    }
                    str = str + export.GetProductXML(current.ProductID, Lang);
                }
            }
            finally
            {
                if (enumerator is IDisposable)
                {
                    (enumerator as IDisposable).Dispose();
                }
            }
            return (str + "</root>");
        }

        public string xmlGetProductsInCat(int PortalID, int CatID, string Lang, int ProductTabID = -1)
        {
            Export export = new Export();
            string str = "";
            if (CatID >= 0)
            {
                IEnumerator enumerator=null;
                ArrayList list = this.GetProductList(PortalID, CatID, Lang, 1, 50, false);
                str = str + "<root>";
                try
                {
                    enumerator = list.GetEnumerator();
                    while (enumerator.MoveNext())
                    {
                        ProductListInfo current = (ProductListInfo) enumerator.Current;
                        str = str + "<item>";
                        if (ProductTabID >= 0)
                        {
                            str = str + this.getProductLinkXML(current, ProductTabID, CatID);
                        }
                        str = str + export.GetProductXML(current.ProductID, Lang);
                        str = str + "</item>";
                    }
                }
                finally
                {
                    if (enumerator is IDisposable)
                    {
                        (enumerator as IDisposable).Dispose();
                    }
                }
                return (str + "</root>");
            }
            return (str + "<root></root>");
        }
    }
}

